home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / sossnt.zip / SOSSNT / SRC / DEBUG.C < prev    next >
C/C++ Source or Header  |  1993-02-28  |  4KB  |  110 lines

  1. /* Initialization routine for debugging macros */
  2. /*  Call dbg_init() prior to using DBGPRT* functions */
  3. /*  Uses NFSDEBUG and DEBUGFILE environment variables */
  4. /*   Rich Braun @ Kronos, Inc.  Waltham, MA */
  5. /*   31 Jan 91 */
  6.  
  7. #include <time.h>
  8. #include <string.h>
  9. #include "debug.h"
  10.  
  11. struct _dbgflags __dbgflags__ = {0};
  12. FILE   *__dbgfp__;
  13.  
  14. static void prflags();
  15. extern char *strtolower(char*);
  16.  
  17. void dbg_init ()
  18. {
  19. char *dbglist, *dbgfile, *getenv();
  20. int  setflag;
  21. time_t now;
  22.  
  23.     /* The code below looks at the NFSDEBUG environment
  24.      * variable for a list of selected debugging options
  25.      * separated by commas (or colons or semicolons).  Macros
  26.      * scattered through the rest of the code are then enabled
  27.      * to output debugging statements depending on the option
  28.      * flags.
  29.      */
  30.     __dbgfp__ = stderr;
  31.     if ((dbglist = getenv ("NFSDEBUG")) != (char *)NULL) {
  32.     (void) strtolower (dbglist);
  33.     while (*dbglist) {
  34.         if (dbglist[0] == '-') {
  35.         setflag = 0;
  36.         dbglist++;
  37.         } else
  38.             setflag = 1;
  39.         if (!strncmp (dbglist, "all", 3)) {
  40.             __dbgflags__.rpctrace = 1;
  41.             __dbgflags__.mountd   = 1;
  42.         __dbgflags__.nfserr   = 1;
  43.             __dbgflags__.nfsdebug = 1;
  44.             __dbgflags__.nfsdisp  = 1;
  45.             __dbgflags__.nfslookup= 1;
  46.             __dbgflags__.nfsread  = 1;
  47.             __dbgflags__.nfswrite = 1;
  48.         __dbgflags__.nfstime  = 1;
  49.         __dbgflags__.inode    = 1;
  50.         }
  51.         else if (!strncmp (dbglist, "rpctrace", 8))
  52.             __dbgflags__.rpctrace = setflag;
  53.         else if (!strncmp (dbglist, "mountd", 6))
  54.             __dbgflags__.mountd = setflag;
  55.         else if (!strncmp (dbglist, "nfserr", 6))
  56.             __dbgflags__.nfserr = setflag;
  57.         else if (!strncmp (dbglist, "nfsdebug", 8))
  58.             __dbgflags__.nfsdebug = setflag;
  59.         else if (!strncmp (dbglist, "nfsdisp", 7))
  60.             __dbgflags__.nfsdisp = setflag;
  61.         else if (!strncmp (dbglist, "nfslookup", 9))
  62.             __dbgflags__.nfslookup = setflag;
  63.         else if (!strncmp (dbglist, "nfsread", 7))
  64.             __dbgflags__.nfsread = setflag;
  65.         else if (!strncmp (dbglist, "nfswrite", 8))
  66.             __dbgflags__.nfswrite = setflag;
  67.         else if (!strncmp (dbglist, "nfstime", 7))
  68.             __dbgflags__.nfstime = setflag;
  69.         else if (!strncmp (dbglist, "inode", 5))
  70.             __dbgflags__.inode = setflag;
  71.         else
  72.           fprintf (stderr, "DBG-warning:  unable to parse NFSDEBUG='%s'\n",
  73.                dbglist);
  74.         dbglist += strcspn (dbglist, ",:;");
  75.         if (*dbglist) dbglist++;
  76.     }
  77.     if ((dbgfile = getenv ("DEBUGFILE")) != (char *)NULL) {
  78.         fprintf (stderr, "DBG-debugging output logged to %s\n", dbgfile);
  79.         if ((__dbgfp__ = fopen (dbgfile, "a")) == (FILE *) NULL) {
  80.         fprintf (stderr, "DBG: warning, can't open output file\n",
  81.              dbgfile);
  82.         }
  83.         prflags (stderr);
  84.     }
  85.     time (&now);
  86.     fprintf (__dbgfp__, "\n### Initiating debugging %s", 
  87.          ctime (&now));
  88.     prflags (__dbgfp__);
  89.     }
  90. }
  91.  
  92. /* Routine to print debugging flags */
  93.  
  94. static void prflags (fp)
  95. FILE *fp;
  96. {
  97.     (void) fprintf (fp,"DBG-debugging options set: ");
  98.     if (__dbgflags__.rpctrace) (void) fprintf (fp, "rpctrace ");
  99.     if (__dbgflags__.mountd)   (void) fprintf (fp, "mountd ");
  100.     if (__dbgflags__.nfserr)   (void) fprintf (fp, "nfserr ");
  101.     if (__dbgflags__.nfsdebug) (void) fprintf (fp, "nfsdebug ");
  102.     if (__dbgflags__.nfsdisp)  (void) fprintf (fp, "nfsdisp ");
  103.     if (__dbgflags__.nfslookup)(void) fprintf (fp, "nfslookup ");
  104.     if (__dbgflags__.nfsread)  (void) fprintf (fp, "nfsread ");
  105.     if (__dbgflags__.nfswrite) (void) fprintf (fp, "nfswrite ");
  106.     if (__dbgflags__.nfstime)  (void) fprintf (fp, "nfstime ");
  107.     if (__dbgflags__.inode)    (void) fprintf (fp, "inode ");
  108.     (void) fprintf (fp, "\n");
  109. }
  110.